<?php
//把这个文件放在项目根目录直接访问
$row = $dir = $html = $php = $js = $css = $png = $jpg = $txt = $other = $php1 = $php2 = 0;
function jieMi($filename){
	global $row, $php1, $php2;
	$f_content = file_get_contents($filename);
	preg_match('/eval\(\'\$O0O000/', $f_content, $matches, PREG_OFFSET_CAPTURE);
	preg_match('/";eval/', $f_content, $matches2, PREG_OFFSET_CAPTURE);
	if($matches && $matches2){
		$php1++;
		$len = strlen($f_content);
		$start = $matches[0][1];
		$length = $matches2[0][1] - $len;
		$str = substr($f_content, $start + 15, $length);
		$a = substr($str,52*2);
		$b = substr($str,52,52);
		$c = substr($str,0,52);
		$qq = base64_decode(strtr($a ,$b, $c));
		$fpp1 = fopen($filename, 'w');
		$back = fwrite($fpp1, $qq);
		if($back){
			echo $row."、文件： ".$filename." 解密成功！ 解密写入 ".$back." 字节。<br>";
		}else{
			echo $row."、解密文件 ".$filename." 时出现写入出错！<br>";
		}
	}else{
		$php2++;
		echo $row."、文件 ".$filename." 是明文代码。<br>";
	}
}

function getdir($path) {
	global $row,$dir,$html,$php,$js,$css,$png,$jpg,$txt,$other;
	$arr = scandir($path);
	foreach ($arr as $v) {
		if ($v != "." && $v != "..") {
			$row++;
			if (is_dir($path . "/" . $v)) {
				$dir++;
				echo "<hr>";
				echo $row."、目录：" . $path . "/" . $v;
				echo "<br>";
				getdir($path . "/" . $v);
			} else {
				$ext = substr($v, (strrpos($v, ".") + 1));
				if ($ext == 'html') {
					$html++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个HTML文件！";
				} elseif ($ext == 'php') {
					$php++;
					jieMi($path."/".$v);
				} elseif ($ext == 'js') {
					$js++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个JS文件！";
				} elseif ($ext == 'css') {
					$css++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个CSS文件！";
				} elseif ($ext == 'png') {
					$png++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个png图片！";
				} elseif ($ext == 'jpg') {
					$jpg++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个jpg图片！";
				} elseif ($ext == 'txt') {
					$txt++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个txt文档！";
				} else {
					$other++;
					echo $row."、文件：" . $path . "/" . $v . "==》》这是一个其他文件！";
				}
				echo "<br>";
			}
		}
	}
}
function sta(){
	global $row,$dir,$html,$php,$js,$css,$png,$jpg,$txt,$other,$php1,$php2;
	echo "<hr>";
	getdir(".");

	echo "<hr><hr>";
	echo "本次解码统计：共递归文件夹 " . $dir . "个!";
	echo "<br>";
	echo "遍历的文件总计: " . ($html+$php+$js+$css+$png+$jpg+$txt+$other) . " 个!";
	echo "<br>";
	echo "共遍历HTML文件 " . $html . " 个!";
	echo "<br>";
	echo "共遍历PHP文件 " . $php . " 个!"." 其中解码 ".$php1." 个，明码 ".$php2." 个。";
	echo "<br>";
	echo "共遍历JS文件 " . $js . " 个!";
	echo "<br>";
	echo "共遍历CSS文件 " . $css . " 个!";
	echo "<br>";
	echo "共遍历png图片文件 " . $png . " 个!";
	echo "<br>";
	echo "共遍历jpg图片文件 " . $jpg . " 个!";
	echo "<br>";
	echo "共遍历txt文件 " . $txt . " 个!";
	echo "<br>";
	echo "共遍历其他文件 " . $other . " 个！<br>";
}
sta();
?>